﻿@using DualControl.CommonServices
@using DualControl.RiskPoints.Dtos

@model Abp.Application.Services.Dto.ListResultDto<RiskPointListDto>
@using X.PagedList.Mvc.Core; @*import this so we get our HTML Helper*@
@using X.PagedList; @*import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)*@

@inject ICommonService CommonService

@{
    ViewData["Title"] = "风险评估";
}

@section scripts
    {
    <environment names="Development">
        <script src="~/view-resources/Views/HazardSources/RiskFactorEvaluation.js" asp-append-version="true"></script>
    </environment>
    <environment names="Staging,Production">
        <script src="~/view-resources/Views/HazardSources/RiskFactorEvaluation.js" asp-append-version="true"></script>
    </environment>
}
<style>
    .table tbody tr td {
        vertical-align: middle;
    }
</style>

<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    @L("RiskFactorEvaluation")
                </h2>
                <ul class="header-dropdown m-r--5">
                    <li class="dropdown">
                        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            <i class="material-icons">more_vert</i>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li><a id="RefreshButton" href="javascript:void(0);" class="waves-effect waves-block"><i class="material-icons">refresh</i>@L("Refresh")</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div class="body table-responsive">
                @foreach (var riskpoint in ViewBag.PageOfRiskPointListDto)
                {
                    <div class="panel panel-primary">
                        <div class="panel-heading"><h3 class="panel-title">
    风险点编码：@riskpoint.Code &nbsp; 车间/班组：@CommonService.GetOrganizationUnits().SingleOrDefault(c => c.Key == riskpoint.OrganizationUnitId).Value   &nbsp; 区域/工段   @riskpoint.AreaOrSection&nbsp; 风险点名称：@riskpoint.Name
    &nbsp;</h3>
                        </div>
                      
                        <table class="table">
                            <tr width="10%"><th>序号</th><th width="15%">作业步骤</th><th width="30%">危险因素</th><th  width="10%">导致事故类型</th><th>L</th><th>E</th><th>C</th><th>D</th><th>风险等级</th><th>颜色</th><th>操作</th></tr>
                            @{ if (riskpoint.HazardSources.Count > 0)
                                {
                                    int i = 0;
                                    float D=0;
                                    @foreach (var hazardsource in riskpoint.HazardSources)
                                    {
                                        i++;
                                        if (hazardsource.L!=null && hazardsource.E!=null && hazardsource.C !=null)
                                        {
                                            D = hazardsource.L * hazardsource.E * hazardsource.C;
                                        }
                                        else
                                        {
                                            D = 0;

                                        }
                            <tr>
                                <td width="5%">@i.</td>
                                <td>@hazardsource.HazardSourceName</td>
                                <td>@hazardsource.RiskFactor  </td>
                                <td>
                                  

                                    @{
                                        string space = " ";
                                        if (hazardsource.AccidentTypesForView != null)
                                        {
                                            foreach (var accident in hazardsource.AccidentTypesForView)
                                            {
                                                @accident
                                                @space
                                            }
                                        }
                                    }



                                </td>
                                <td>@if (hazardsource.L > 0){@hazardsource.L}                                                            </td>
                                <td>
                                    @if (hazardsource.E > 0)
                                    {@hazardsource.E}
                                 </td>
                                <td>
                                    @if (hazardsource.C > 0)
                                    {@hazardsource.C}
                                 </td>
                                <td>@if (D > 0) {@D}</td>
                                <td>
                                    @if(hazardsource.RiskLevel>0)
                                    {@hazardsource.RiskLevel}
                                </td>
                                <td style="background-color:@hazardsource.RiskColor">
                                </td>
                                <td>
                                    <span class="glyphicon glyphicon-pencil"></span>
                                    <button class="edit-hazardsource" data-hazardsource-id="@hazardsource.Id" data-hazardsource-l="@hazardsource.L" data-hazardsource-e="@hazardsource.E" data-hazardsource-c="@hazardsource.C" data-toggle="modal" data-target="#RiskFactorEvaluationModal">编辑</button>
                                </td>
                            </tr>
                                    }
                                }
                            }
                        </table>
                    </div>
                }

            </div>
        </div>
    </div>
</div>

@Html.PagedListPager((IPagedList)ViewBag.PageOfRiskPointListDto, page => Url.Action("Index", new { page }))

<div class="modal fade" id="RiskFactorEvaluationModal" tabindex="-1" role="dialog" aria-labelledby="HazardSourceCreateModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    <span>危害因素风险评价</span>
                </h4>
            </div>
            <div class="modal-body">
                <form name="RiskFactorEvaluationForm" role="form" novalidate class="form-validation">
                    <input type="hidden" name="Id" id="Id" />
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane animated fadeIn active" id="create-org-details">
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">危害发生的可能性L(取值范围为0.1-10)</label>
                                        <input class="form-control" type="text" id="L" name="L" min="0.1" max="10" required  placeholder="L值，取值范围为0.1-10">
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">危害暴露的频繁程度E(取值范围为0.5-10)</label>
                                        <input class="form-control" type="text" id="E" name="E" required  min="0.5" max="10"placeholder="E值，取值范围为0.5-10">
                                    </div>
                                </div>
                            </div>

                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">事故后果的严重性C(取值范围为1-100)</label>
                                        <input class="form-control" type="text" id="C" name="C" required min="0.5" max="100" placeholder="C值，取值范围为0.5-100">
                                    </div>
                               </div>                              
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
                        <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

